cmake_minimum_required(VERSION 3.1)#最低版本要求

project( Armadillo_Template )#工程名称


#Armadillo
option(USE_Armadillo "Need the Armadillo module or not" ON)
mark_as_advanced(USE_Armadillo) # 
set(Armadillo_DIR "" CACHE PATH "Armadillo path")
if( USE_Armadillo )
	message(STATUS "find Armadillo.")
	mark_as_advanced(Armadillo_DIR)
	if(NOT Armadillo_DIR)
		message(FATAL_ERROR "cannot find Armadillo_DIR path.")
	else()
		set(Armadillo_INCLUDE_DIR "${Armadillo_DIR}/include")
		set(Armadillo_LIBRARY_DIR "${Armadillo_DIR}/examples/lib_win64")
		message(STATUS "    include path: ${Armadillo_INCLUDE_DIR}")
		message(STATUS "    library path: ${Armadillo_LIBRARY_DIR}")
	endif()
	include_directories(${Armadillo_INCLUDE_DIR})
	link_directories(${Armadillo_LIBRARY_DIR})
	link_libraries(${Armadillo_LIBRARY_DIR}/*.lib)
endif()
#Matlab
option(USE_MATLAB "Need the matlab module or not" ON)
mark_as_advanced(USE_MATLAB) # 安装的matlab必须是64位

set(MATLAB_DIR "" CACHE PATH "matlab path")
if( USE_MATLAB )
	message(STATUS "find matlab.")
	mark_as_advanced(MATLIB_DIR)
	if(NOT MATLAB_DIR)
		message(FATAL_ERROR "cannot find matlab path.")
	else()
		set(MATLAB_INCLUDE_DIR "${MATLAB_DIR}/include")
		set(MATLAB_LIBRARY_DIR "${MATLAB_DIR}/lib")
		list(APPEND MATLAB_INCLUDE_DIR ${MATLAB_INCLUDE_DIR}/win64)
		set(MATLAB_LIBRARY_DIR ${MATLAB_LIBRARY_DIR}/win64/microsoft)
		message(STATUS "    include path: ${MATLAB_INCLUDE_DIR}")
		message(STATUS "    library path: ${MATLAB_LIBRARY_DIR}")
	endif()
	include_directories(${MATLAB_INCLUDE_DIR})
	link_directories(${MATLAB_LIBRARY_DIR})
	link_libraries(
	libmat.lib
	libmx.lib
	libmex.lib
	libeng.lib)
endif()
# 设置输出路径
if( NOT LIBRARY_OUTPUT_PATH )
  set( LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
    "Single output directory for building all libraries." )
endif()
if( NOT EXECUTABLE_OUTPUT_PATH )
  set( EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
    "Single output directory for building all executables." )
endif()
mark_as_advanced( LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH )

# 设置输出路径
message(STATUS "    EXECUTABLE_OUTPUT_PATH path: ${EXECUTABLE_OUTPUT_PATH}")

# 1 拷贝文件夹里的文件
file(COPY ${Armadillo_LIBRARY_DIR}/blas_win64_MT.dll  DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Debug)
file(COPY ${Armadillo_LIBRARY_DIR}/lapack_win64_MT.dll  DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Debug)
file(COPY ${Armadillo_LIBRARY_DIR}/blas_win64_MT.dll  DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Release)
file(COPY ${Armadillo_LIBRARY_DIR}/lapack_win64_MT.dll  DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Release)

file(GLOB hdr_files  *.h)
file(GLOB src_files  *.cpp *.c)
source_group("Header Files" FILES ${hdr_files})
source_group("Source Files" FILES ${src_files})
add_executable(${PROJECT_NAME} ${hdr_files} ${src_files})





